<?php
namespace app\controllers;

use Yii;
use yii\web\Controller;
use yii\filters\VerbFilter;
use yii\filters\AccessControl;

/**
 * Site controller
 */
class SiteController extends Controller
{
    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return [
            'access' => [
                'class' => AccessControl::className(),
                'only' => ['logout', 'signup'],
                'rules' => [
                    [
                        'actions' => ['signup'],
                        'allow' => true,
                        'roles' => ['?'],
                    ],
                    [
                        'actions' => ['logout'],
                        'allow' => true,
                        'roles' => ['@'],
                    ],
                ],
            ],
        ];
    }

    /**
     * @inheritdoc
     */
    public function actions()
    {
        return [
            'error' => [
                'class' => 'yii\web\ErrorAction',
            ],
            'captcha' => [
                'class' => 'common\components\CaptchaAction',
                //'fixedVerifyCode' => (string) mt_rand(1111, 9999),
            ],
        ];
    }

    /**
     * Displays homepage.
     *
     * @return mixed
     */
    public function actionIndex()
    {
        return $this->redirect('taobao/quan');
        if (! Yii::$app->user->isGuest) {            
            if ( ! Yii::$app->user->identity->profile->qq) {
                Yii::$app->session->addFlash('error', '请设置QQ号！');
                return $this->redirect(['user/settings/profile']);
            }
        }
        return $this->render('index');
    }
    /**
     * Displays homepage.
     *
     * @return mixed
     */
    public function actionTaoke()
    {
		$this->layout = false;
		$type = Yii::$app->request->get('type', 'detail');
		$item_id = Yii::$app->request->get('item_id');
		$url = Yii::$app->request->get('url');
        return $this->render('taoke', ['type' => $type, 'item_id' => $item_id, 'url' => $url]);
    }
    
    /**
     * Logs out the current user.
     *
     * @return mixed
     */
    public function actionLogout()
    {
        Yii::$app->user->logout();

        return $this->goHome();
    }
}
